package com.yxkj.syh.app.huarong.bean;


import com.syh.app.basic.App;
import com.yxkj.syh.app.huarong.R;
import com.yxkj.syh.app.huarong.constants.OrderStatus;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 采购单
 * </p>
 *
 * @author dengyejun
 * @since 2020-04-24
 */
public class OrderInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;

    //    @ApiModelProperty(value = "标记")
    private int flag;

    //    @ApiModelProperty(value = "员工")
    private Long creatorId;

    //    @ApiModelProperty(value = "业务员")
    private Long salesmanId;
    private Buyer salesman;

//    @ApiModelProperty(value = "收货人")
//    private Long consigneeId;
//    private ShiroUser consignee;


    //    @ApiModelProperty(value = "供应商Id")
    private Long supplierId;

    //    @ApiModelProperty(value = "收款信息")
    private Long bankId;

    //    @ApiModelProperty(value = "供应商")
    private String supplierName;

    //    @ApiModelProperty(value = "纸厂")
    private Long destinationId;
    //    @ApiModelProperty(value = "纸厂")
    private String destination;

    //    @ApiModelProperty(value = "编码")
    private String no;

    //    @ApiModelProperty(value = "货品链")
    private String productIds;
    private String productNames;

    //    @ApiModelProperty(value = "采购量(吨)")
    private BigDecimal quantity = BigDecimal.ZERO;

    //    @ApiModelProperty(value = "结算量(吨)")
    private BigDecimal settleQuantity;

    //    @ApiModelProperty(value = "扣点(吨)")
    private BigDecimal deductQuantity;

    //    @ApiModelProperty(value = "货款总额")
    private BigDecimal totalAmount;

    //    @ApiModelProperty(value = "打包数")
    private Integer packages = 0;

    //    @ApiModelProperty(value = "扣点金额")
    private BigDecimal deductAmount;

    //    @ApiModelProperty(value = "运费")
    private BigDecimal freight;

    //    @ApiModelProperty(value = "结算金额")
    private BigDecimal actualAmount;

    // @ApiModelProperty(value = "实付金额")
    private BigDecimal paymentAmount;

    //    @ApiModelProperty(value = "备注")
    private String remark;

    //    @ApiModelProperty(value = "状态")
    private Integer status;

    private String startArea;

    private String endArea;

    //    @ApiModelProperty(value = "发货信息")
    private Payment payment;

    //    @ApiModelProperty(value = "发货信息")
    private UserMainInfo startLocation;

    //    @ApiModelProperty(value = "收货信息")
    private UserMainInfo endLocation;

    private String creator;
    private String updator;
    private String createTime;
    private String updateTime;
    private String pricingTime;
    private String license;

    /**
     * 货品明细
     */
    private List<Goods> details = new ArrayList<>();

    private List<OrderProcess> orderProcessList = new ArrayList<>();

    public List<OrderProcess> getOrderProcessList() {
        return orderProcessList;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }


    public int getFlag() {
        return flag;
    }

    public String getLicense() {
        return license;
    }

    public void setLicense(String license) {
        this.license = license;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public Long getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(Long creatorId) {
        this.creatorId = creatorId;
    }

    public Long getSalesmanId() {
        return salesmanId;
    }

    public void setSalesmanId(Long salesmanId) {
        this.salesmanId = salesmanId;
    }

    public Buyer getSalesman() {
        return salesman;
    }

    public void setSalesman(Buyer salesman) {
        this.salesman = salesman;
    }

    public Long getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(Long supplierId) {
        this.supplierId = supplierId;
    }

    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    public String getSupplierName() {
        return supplierName;
    }

    public void setSupplierName(String supplierName) {
        this.supplierName = supplierName;
    }

    public Long getDestinationId() {
        return destinationId;
    }

    public void setDestinationId(Long destinationId) {
        this.destinationId = destinationId;
    }

    public String getDestination() {
        return destination;
    }

    public void setDestination(String destination) {
        this.destination = destination;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getProductIds() {
        return productIds;
    }

    public void setProductIds(String productIds) {
        this.productIds = productIds;
    }

    public String getProductNames() {
        return productNames;
    }

    public void setProductNames(String productNames) {
        this.productNames = productNames;
    }

    public BigDecimal getQuantity() {
        return quantity;
    }

    public void setQuantity(BigDecimal quantity) {
        this.quantity = quantity;
    }

    public BigDecimal getSettleQuantity() {
        return settleQuantity;
    }

    public void setSettleQuantity(BigDecimal settleQuantity) {
        this.settleQuantity = settleQuantity;
    }

    public BigDecimal getDeductQuantity() {
        return deductQuantity;
    }

    public void setDeductQuantity(BigDecimal deductQuantity) {
        this.deductQuantity = deductQuantity;
    }

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public Integer getPackages() {
        return packages;
    }

    public void setPackages(Integer packages) {
        this.packages = packages;
    }

    public BigDecimal getDeductAmount() {
        return deductAmount;
    }

    public void setDeductAmount(BigDecimal deductAmount) {
        this.deductAmount = deductAmount;
    }

    public BigDecimal getFreight() {
        return freight;
    }

    public void setFreight(BigDecimal freight) {
        this.freight = freight;
    }

    public BigDecimal getActualAmount() {
        return actualAmount;
    }

    public BigDecimal getPaymentAmount() {
        return paymentAmount;
    }

    public void setPaymentAmount(BigDecimal paymentAmount) {
        this.paymentAmount = paymentAmount;
    }

    public void setActualAmount(BigDecimal actualAmount) {
        this.actualAmount = actualAmount;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getStartArea() {
        return startArea;
    }

    public void setStartArea(String startArea) {
        this.startArea = startArea;
    }

    public String getEndArea() {
        return endArea;
    }

    public void setEndArea(String endArea) {
        this.endArea = endArea;
    }

    public UserMainInfo getStartLocation() {
        return startLocation;
    }

    public void setStartLocation(UserMainInfo startLocation) {
        this.startLocation = startLocation;
    }

    public UserMainInfo getEndLocation() {
        return endLocation;
    }

    public void setEndLocation(UserMainInfo endLocation) {
        this.endLocation = endLocation;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public String getUpdator() {
        return updator;
    }

    public void setUpdator(String updator) {
        this.updator = updator;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public String getPricingTime() {
        return pricingTime;
    }

    public void setPricingTime(String pricingTime) {
        this.pricingTime = pricingTime;
    }

    public List<Goods> getDetails() {
        return details;
    }

    public void setDetails(List<Goods> details) {
        this.details = details;
    }

    public void setOrderProcessList(List<OrderProcess> orderProcessList) {
        this.orderProcessList = orderProcessList;
    }

    public Payment getPayment() {
        return payment;
    }

    public void setPayment(Payment payment) {
        this.payment = payment;
    }

    public Long getId() {
        return id;
    }

    public Map<String,Object> getCreatRequest(){
        Map<String,Object> pMap = new HashMap<>();
        pMap.put("destinationId",destinationId);
        pMap.put("bankId",bankId);
        pMap.put("salesmanId",salesmanId);
        pMap.put("supplierId",supplierId);
        List<Map<String,Object>> goodsList = new ArrayList<>();
        for (Goods goods:details){
            Map<String,Object> goodsMap = new HashMap<>();
            goodsMap.put("quantity",goods.getQuantity());
            goodsMap.put("packages",goods.getPackages());
            goodsMap.put("productNo",goods.getVal());
            goodsMap.put("productId",goods.getCode());
            goodsMap.put("name",goods.getName());
            goodsList.add(goodsMap);
        }
        pMap.put("details",goodsList);
        return pMap;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String orderText() {
        return "订单号：" + no;
    }

    public String statusText() {
        switch (status) {
            case OrderStatus.WAIT:
                return "待发货";
            case OrderStatus.WAIT_ECEIVING:
                return "待收货";
            case OrderStatus.WAIT_PRICING:
                return "待定价";
            case OrderStatus.WAIT_ADJUST:
            case OrderStatus.IN_APPROVAL:
                return "待核算";
            case OrderStatus.WAIT_PAYMENT:
                return "待结算";
            case OrderStatus.COMPLETED:
                return "已完成";
            case OrderStatus.CANCELED:
                return "已取消";
            case OrderStatus.RETURN:
                return "已退货";
            default:
                return "";
        }
    }

    public int statusTextColor() {
        switch (status) {
            case OrderStatus.WAIT:
            case OrderStatus.WAIT_ECEIVING:
            case OrderStatus.WAIT_PRICING:
            case OrderStatus.WAIT_ADJUST:
            case OrderStatus.WAIT_PAYMENT:
            case OrderStatus.RETURN:
            case OrderStatus.IN_APPROVAL:
                return App.getApplication().getColor(R.color.defaultOrange);
            case OrderStatus.COMPLETED:
                return App.getApplication().getColor(R.color.defaultGreen);
            case OrderStatus.CANCELED:
                return App.getApplication().getColor(R.color.textColor5);

            default:
                return App.getApplication().getColor(R.color.textColor5);
        }
    }

    public String getGoodsStr() {
        return productNames.replace("|", "\n");
    }

    /**
     * 异常类型
     *
     * @return
     */
    public String exText() {
        if (flag == OrderStatus.FLAG_REJECT) {
            return "被驳回";
        } else if (flag == OrderStatus.FLAG_PART_RETURN) {
            return "部分退货";
        }
        return "";
    }

}
